var Scene2D = (function(){
    function Scene2DClass(uiClass){
        this._isInit = false;
        this.___uiKey = '';
        this.___uiClass = uiClass;
        this._node = null;
    }

    Scene2DClass.prototype.createNode = function(uiClass){
        if(uiClass) {
            var node = new uiClass();
            for (var p in node) {
                if(!this.hasOwnProperty(p))
                    this[p] = node[p];
            }
        } else {
            node = new Laya.Sprite();
        }
        node.pos((Config.GameWidth-node.width)/2, (Config.GameHeight-node.height)/2); 
        this._node = node;
        this._node.visible = false;
    };

    Scene2DClass.prototype.init = function(key){
        this.___uiKey = key;
        this.___uiClass = Laya.ClassUtils.getClass("ui.scenes."+this.___uiKey+"UI");
        this.createNode(this.___uiClass);
    };


    Scene2DClass.prototype.initScene = function(node){
        // override
    };

    Scene2DClass.prototype.onActive = function(from){
        // override
    };

    Scene2DClass.prototype.onInActive = function(){
        // override
    };

    Scene2DClass.prototype.active = function(from){
        if(!this._isInit){            
            Laya.stage.addChild(this._node); 
            this._isInit = true;
            this.initScene(this._node);
        }
        this._node.visible = true;
        this.onActive(from);
    };

    Scene2DClass.prototype.inActive = function(){
        this.onInActive( );
        if(this._node){
            this._node.visible = false;
        }
    };

    Scene2DClass.prototype._uninit = function(){
        Tool.log("---Scene2D::_uninit name="+this.___uiKey);
        if(this._isInit){
            this.onInActive();
        }
        if(this._node){
            this._node.destroy();
        }
    };

    return Scene2DClass;
})();
